Skip to content

Do not let the node's umask decide who can read a segment - #404

Merged
SergioDemianLerner merged 1 commit into
mainfrom
segbuild/readable-output
Nov 21, 2026
Merged

SergioDemianLerner merged 1 commit into
mainfrom
segbuild/readable-output

Conversation

@SDL-A1

@SDL-A1 SDL-A1 commented Nov 21, 2026 •

Copy link
Copy Markdown
Collaborator

Two defects found by enabling segbuild on the mainnet node and reading what it actually did. Neither would have surfaced any other way — both tests and CI pass with them present.

A segment nothing could read

The node runs under UMask=0077. Sensible hardening, and the builder inherited it, so the first segment it produced was openable by nothing but the node:

drwx--S---  909-9420001-9429888     ← built by the node
-rw-------  BOUNDARIES
-rw-------  BUILT
drwxrwsr-x  055-5849091-5895185     ← built offline, under a normal umask

That is the worst shape a failure can take here, because it is silent and it looks like something else:

INFO Built 909-9420001-9429888: 9888 blocks, 9888 state roots verified, 2 table(s), 92 blk/s

All true. The segment is correct. A consumer then gets a permission error, which looks nothing like "this segment is fine, you just cannot read it" — and du reports 1 MB, because it cannot descend into it.

The set exists to be read by other processes, so the mode is now set explicitly after the rename rather than inherited: 0755 for directories, 0644 for files, and the same for the logs, which are operational state a human and the offline tools read. Loosening the unit's umask would have been the wrong fix — the node's hardening is not the problem.

Best-effort and not fatal: a segment that is correct but awkwardly permissioned is still correct, so a failure logs the chmod that fixes it and carries on. #[cfg(unix)]-gated, because CI builds this on Windows too.

The same defect one layer up: inert, and quiet about it

The node started with the set owned by the user who had built it offline, could not append BOUNDARIES, said so once:

WARN segbuild: could not record the catch-up boundary at #9429867:
     opening /var/lib/rustock/segbuild/BOUNDARIES: Permission denied (os error 13)

…and then had nothing further to say, because the next attempt would have come a gigabyte of writes later — about a month. The feature was inert and the log looked healthy.

Startup now probes the directory by writing a file and removing it, and refuses with the commands that fix it:

--segbuild-out /var/lib/rustock/segbuild is not writable by this node (…). The
segment set is often owned by whoever built it offline, while the node runs as
its own user. Give the node ownership, or group write with setgid so both keep
access:
  chown -R <node-user>:<group> /var/lib/rustock/segbuild
  chmod -R g+w /var/lib/rustock/segbuild
  find /var/lib/rustock/segbuild -type d -exec chmod g+s {} +

That is §7.2's rule applied where it belongs: "the set is current" is not the same as "this node can extend it", and a config error that makes the feature impossible goes at startup, before anything is serving, rather than into a single warning.

What the node did once both were understood

WARN segbuild: the set ends at #9420000 and this node has executed to #9430888, a gap of
     10888 blocks. The collector has not been beneath it (watermark #9342320), so it is
     still buildable, and all but the last 1000 blocks of it are cut as a range of their own now.
INFO segbuild: recorded a boundary at #9429888 so #9420001..#9429888 is built as a range
     of its own, starting on the next tick -- it is already 1000 blocks settled
INFO Building #9420001..#9429888 (0 MB accumulated), 1 range(s) pending
INFO Seeded #9420001..#9429888 from #9420000 root 0x95e61859d4c351cd09c0106728706ecba…
INFO Built 909-9420001-9429888: 9888 blocks, 9888 state roots verified, 2 table(s), 92 blk/s

108 seconds for a 10,888-block coverage gap, every state root verified, into a 232 MB segment, recorded against the chain's own hash at #9,429,888 — checked independently with block_info, which reports 9dc24584 for that height, matching BUILT. No HALTED, no UNCOVERED.

Two numbers worth recording from that run, because both differ from what the design assumed:

  • The index is 909, not 098. next_index continues from the highest present, and the set holds 900–908 from the pre-fork work. Correct per §4.4, and worth knowing before someone greps for 0NN-.
  • 232 MB for 9,888 blocks, and that is not evidence about the 1 GB target. This range was cut by cut_at, the startup catch-up cut, which ignores the counter — BOUNDARIES records its approx_bytes as 0. Its length came from the size of the gap, not from the target. An earlier draft of this description extrapolated "~43,000-block segments" from it; that is wrong twice over, and the real figure is unknown until the first size-cut segment. See the note below, which is the part worth acting on.

A target in write-bytes, a property about read-bytes

--segbuild-target-mb counts bytes written by executed blocks. A segment holds its range's read set — every node the replay touched — which is a superset. The existing set shows how far apart they are:

segment on disk blocks KB/block
094-9017692-9133347 4,348 MB 115,656 38.5
097-9230009-9420000 2,718 MB 189,992 14.6
055-5849091-5895185 1,483 MB 46,095 32.9
909-9420001-9429888 232 MB 9,888 24.0

So a 1 GB write target will not produce a 1 GB segment on disk — and "fits in a consumer's memory", which is the property the byte target exists to protect, is about the sealed size. None of the segments above was byte-targeted: the offline build took its boundaries from a chunk list, so this builder is the first thing that actually cuts by bytes, and the ratio is era-dependent.

Nothing here changes that, deliberately — the first size-cut segment will measure it, and --segbuild-target-mb is a restart away from being adjusted. Flagging it rather than guessing a correction.

Verification

CLI bin 164, execution segment_build 5 (new test reproduces UMask=0077 and asserts a consumer can read the result), clippy clean across rustock-cli, rustock-execution and rustock-storage with --all-targets.

🤖 Generated with Claude Code

Both of these were found by enabling segbuild on the mainnet node and reading
what it actually did, which is the only way either would have surfaced.

The node runs under `UMask=0077`. Sensible hardening, and the builder inherited
it, so the first segment it produced was `drwx--S---`: correct, verified, and
openable by nothing but the node.

    drwx--S---  909-9420001-9429888     <- built by the node
    -rw-------  BOUNDARIES
    -rw-------  BUILT
    drwxrwsr-x  055-5849091-5895185     <- built offline, under a normal umask

That is the worst shape a failure can take here, because it is silent and it
looks like something else. The build log says 9,888 blocks and 9,888 state roots
verified, which is true. A consumer then gets a permission error, which looks
nothing like "this segment is fine, you just cannot read it" -- and `du` reports
1 MB, because it cannot descend. The set exists to be read by other processes,
so the mode is now set explicitly after the rename rather than inherited: 0755
for directories, 0644 for files, and the same for the logs, which are
operational state a human and the offline tools read. Loosening the unit's umask
would have been the wrong fix; the node's hardening is not the problem.

Best-effort and not fatal: a segment that is correct but awkwardly permissioned
is still correct, so a failure logs the `chmod` that fixes it and carries on.
Unix only, gated, because CI builds this on Windows too.

The second half is the same defect one layer up. The node started with the set
owned by the user who had built it offline, could not append `BOUNDARIES`, said
so once:

    WARN segbuild: could not record the catch-up boundary at #9429867:
         opening /var/lib/rustock/segbuild/BOUNDARIES: Permission denied

and then had nothing further to say, because the next attempt would have come a
gigabyte of writes later -- about a month. The feature was inert and the log
looked healthy. So startup now probes the directory by writing a file and
removing it, and refuses with the `chown`/`chmod`/`setgid` commands that fix it.
That is §7.2's rule: "the set is current" is not the same as "this node can
extend it", and a config error that makes the feature impossible belongs at
startup, before anything is serving, not in a single warning.

With both in place the node closed its 10,888-block coverage gap in 108 seconds
at 92 blk/s, verifying every state root, into a 232 MB segment recorded against
the chain's own hash at #9,429,888.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
@SergioDemianLerner
SergioDemianLerner merged commit 9b26fdf into main Nov 21, 2026
9 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants